<!DOCTYPE html>
<html>

	<head>
		<meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1">
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../../css/iuapmobile.um.css">
		<link rel="stylesheet" href="../../css/font-icons.css">
		<link rel="stylesheet" type="text/css" href="../../css/iuapmobile.um.listview.css">
		<link rel="stylesheet" href="../../css/iscroll.css" />
		<script src="../../js/summer.js"></script>
		<script src="../../js/jquery.min.js"></script>
		<script src="../../js/iscroll.js"></script>
		<script src="../../js/Frameworks/iuapmobile.frameworks.ui.js"></script>
		<script type="text/javascript" src="../../js/knockout.js"></script>
		<script type="text/javascript" src="../../js/Frameworks/iuapmobile.frameworks.listview.js"></script>
		<style>
			#select1_dummy,
			#select2_dummy,
			#select3_dummy {
				border: none;
				padding-left: 10px;
				color: #555;
				font-size: 17px;
				text-align: right;
				margin-right: 20px;
				width: 100%;
			}
			
			#select1_dummy:disabled,
			#select2_dummy:disabled,
			#select3_dummy:disabled {
				background: #fff;
			}
		</style>

		<style>
			.msg-info {
				position: relative;
			}
			
			.msg-info .um-badge {
				position: absolute;
				right: -10px;
				font-size: 12px;
			}
			
			.msg-header {
				width: 40px;
				height: 40px;
				line-height: 40px;
				background: blue;
				border-radius: 50%;
				text-align: center;
				color: white;
			}
			/**
			 * 显示不完全的问题解决方案 
			 */
			
			.um-text-overflow {
				white-space: normal;
			}
		</style>
	</head>

	<body class="f14">
		<div class="um-win" id="installed">
			<div class="um-header">
				<h3>派工页面</h3>
				<a href="#" class="um-back back">返回</a>
				<a class="um-header-right" onclick="submitdata1();">提交</a>
			</div>

			<div class="um-content" ng-app="myApp" ng-controller="myCtrl">
				<ul class="um-list" style="min-height: 80px">

					<li class="um-list-item">
						<div class="um-list-item-inner">
							<span class="h pa um-box-vc um-red f20 pl5">*</span>
							<div class="um-list-item-left pl15">
								设备签收人:
							</div>
							<div class="um-list-item-right">
								<select id='select1' class="select" ng-model="receiver">
									<option ng-repeat="i in persion" value="{{i.pk_doc}}">{{i.doc_name}}</option>
								</select>
							</div>
						</div>
					</li>
					<li class="um-list-item">
						<div class="um-list-item-inner">
							<span class="h pa um-box-vc um-red f20 pl5">*</span>
							<div class="um-list-item-left pl15">
								施工执行人:
							</div>
							<div class="um-list-item-right">
								<select id='select2' class="select" ng-model="transactor">
									<option ng-repeat="r in installer" value="{{r.pk_doc}}">{{r.doc_name}}</option>
								</select>
							</div>
						</div>
					</li>
				</ul>
				<label class="um-check-inline">
					<input name="um-checkbox-inline" id="selectAll" type="checkbox"  value="全选">
					<span class="um-icon-checkbox um-css3-vc"></span> <span class="um-black ml5" id="selectAllText">全选</span>
				</label>
				<div class="um-listview-wrap" id="listview">
					<ul class="um-list um-no-active" data-bind="foreach: data">
						<li class="um-listview-row">
							<a href="#" class="um-list-item um-swipe-action um-no-icon">
								<div class="um-list-item-inner">
									<div class="um-list-item-body um-text-overflow f14" style="padding-right:5px;">

										<div class="um-bgc-blue um-white pt5 pb5 ">
											<input type="checkbox" name="che" data-bind="attr: {id: bodyid}"> ︱点位编号:
											<span data-bind="text:dwbh"></span>
										</div>
										<div class="w">
											<div class="um-md-6 w_50 fl mt5 mb5">
												区:<span data-bind="text:qu"></span>
											</div>
											<div class="um-md-6 w_50 fl mt5 mb5">
												所:<span data-bind="text:suo"></span>
											</div>
										</div>
										<div class="w">
											<div class="um-md-6 w_50 fl mt5 mb5">
												商家名称:<span data-bind="text:sjmc"></span>
											</div>
											<div class="um-md-6 w_50 fl mt5 mb5">
												地址:<span data-bind="text:dz"></span>
											</div>
										</div>
										<div class="w">
											<div class="um-md-6 w_50 fl mt5 mb5">
												商圈:<span data-bind="text:sq"></span>
											</div>
											<div class="um-md-6 w_50 fl mt5 mb5">
												设备类型:<span data-bind="text:sblx"></span>
											</div>
										</div>
										<div class="w">
											<div class="um-md-6 w_50 fl mt5 mb5">
												摄像机数量:<span data-bind="text:sxjsl"></span>
											</div>
											<div class="um-md-6 w_50 fl mt5 mb5">
												是否加急:<span data-bind="text:ifjj"></span>
											</div>
										</div>
									</div>
								</div>
							</a>
						</li>
					</ul>
				</div>

			</div>
		</div>
		<script src="../../js/angular.min.js"></script>
		<script>
			var updateList;
			var billid;
			var anscope;
			$(function() {
				var opt = {
					'date': {
						preset: 'date'
					},
					'select': {
						preset: 'select'
					}
				};
				$('.select').scroller('destroy').scroller($.extend(opt['select'], {
					theme: "ios7",
					mode: "scroller",
					display: "bottom",
					animate: ""
				}));
			});

			$(function() {
				var isChecked;
				var ViewModel = function() {};
				var viewModel = new ViewModel();
				//构造控件实例
				var listview = UM.listview("#listview");
				//当前第几页
				viewModel.data = ko.observableArray([]);
				ko.applyBindings(viewModel);
				//绑定叶号，是否第一次bool
				updateList = function() {
					doPost(adressHead.ISjtzImpl, "getAzPgxxList_dail_v2", {
						dataParm: {
							empId: summer.getStorage("userinfo").empId,
							billid: billid,
							status: 1
						}
					}, function(data) {
						if(data.result == 1) {
							try {
								while(viewModel.data.shift()) {}
							} catch(e) {}
							for(var i = 0; i < data.data.length; i++) {
								viewModel.data.push({
									'ids': "id" + i,
									'qu': data.data[i].qu,
									'suo': data.data[i].suo,
									'sq': data.data[i].sq,
									'dwbh': data.data[i].dwbh,
									'sjmc': data.data[i].sjmc,
									'dz': data.data[i].dz,
									'sblx': data.data[i].sblx,
									'sxjsl': data.data[i].sxjsl,
									'ifjj': data.data[i].ifjj == "0" ? "否" : "是",
									'bodyid': data.data[i].bodyid,
									'check': false
								});
							};
							var list = document.getElementsByName("che");
							//对表单中所有的input进行遍历
							for(var i = 0; i < list.length; i++) {
								//判断是否为文本框
								list[i].addEventListener("click", function(e) {
									console.log(this);
									e.stopPropagation();
								})
							}
						} else {
							alerts(data.msg);
						}
						listview.refresh();
					});
				};
				window.bind = function() {
					updateList();
				};
				listview.on("itemClick", function(sender, args) {
					var docnum = viewModel.data()[args.rowIndex].bodyid;
					if($("#" + docnum).is(':checked')) {
						$("#" + docnum).prop("checked", false);
					} else {
						$("#" + docnum).prop("checked", true);
					}
					sender.refresh();
				});
				var select = document.getElementById("selectAll");
				select.addEventListener("change", function(e) {
					var isChecked = $(this).prop("checked");
					$("input[name='che']").prop("checked", isChecked);
				})
			});

			function rebind() {
				window.bind();
			}

			//提交数据
			var submitdatas = new Array();

			function submitdata1() {
				UM.confirm({
					title: '友情提示：',
					text: '是否确认提交',
					btnText: ["取消", "确认"],
					overlay: true,
					ok: function() {
						submitdata();
					},
					cancle: function() {}
				});
			}

			function submitdata() {
				if(!anscope.receiver) {
					alerts("请填写设备签收人");
					return;
				}
				if(!anscope.transactor) {
					alerts("请填写施工执行人");
					return;
				}

				submitdatas = [];

				$('input:checkbox[name=che]:checked').each(function(i,j) {
					submitdatas.push({
						empId: summer.getStorage('userinfo').empId,
						bodyid: j.id,
						billid: billid,
						receiver: anscope.receiver,
						transactor: anscope.transactor,
					});
				});

				if(submitdatas.length == 0) {
					alerts("请选择相应的点位后再试");
					return;
				}

				doPost(adressHead.ISjtzImpl, "acceptDispatch", {
					dataParm: {
						data: submitdatas
					}
				}, function(data) {
					if(data.result == 1) {
						alerts(data.msg);
						updateList();
					}
				});
			}

			$('.select').change(function() {
				$("#" + $(this).attr("id") + "_dummy").val($(this).find("option:selected").text());
			});

			function bindqianshouren(city, sgdw1) {
				var persiondata = city + "_" + sgdw1 + "_02";
				doPost(adressHead.ISjtzImpl, "getBdDoc", {
					dataParm: {
						dostype: persiondata
					}
				}, function(jsons) {
					anscope.persion = jsons;
					anscope.$apply();
					$("#select1_dummy").val("请选择");
				}, null, true);

			}

			function bindzhixingren(city, sgdw1) {
				var persiondata = city + "_" + sgdw1 + "_03";
				doPost(adressHead.ISjtzImpl, "getBdDoc", {
					dataParm: {
						dostype: persiondata
					}
				}, function(jsons) {
					anscope.installer = jsons;
					anscope.$apply();
					$("#select2_dummy").val("请选择");
				}, null, true);

			}

			function isRepeat(arr) {
				var flag = false;
				for(var i = 1; i < arr.length; i++) {
					if(arr[0] != arr[i]) {
						flag = true;
					}
				}
				return flag;

			}

			/**
			 *angular 控件初始化
			 */
			var app = angular.module('myApp', []);
			app.controller('myCtrl', function($scope, $http) {
				anscope = $scope;
				//bindqianshou();
			});
			summerready = function() {
				if(summer.pageParam) {
					billid = summer.pageParam.billid;
					var cs = summer.pageParam.cs;
					var sgdw = summer.pageParam.sgdw;
					bindqianshouren(cs, sgdw);
					bindzhixingren(cs, sgdw);
					updateList();
				}
			}
		</script>

	</body>

</html>
<script type="text/javascript" src="../../js/Myjs/Common.js"></script>